/*
 *	Copyright (C) 2012. PARP Research Group.
 *	<http://perception.inf.um.es>
 *	University of Murcia, Spain.
 *
 *	This file is part of the QVision library.
 *
 *	QVision is free software: you can redistribute it and/or modify
 *	it under the terms of the GNU Lesser General Public License as
 *	published by the Free Software Foundation, version 3 of the License.
 *
 *	QVision is distributed in the hope that it will be useful,
 *	but WITHOUT ANY WARRANTY; without even the implied warranty of
 *	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *	GNU Lesser General Public License for more details.
 *
 *	You should have received a copy of the GNU Lesser General Public
 *	License along with QVision. If not, see <http://www.gnu.org/licenses/>.
 */

/// @file
/// @brief File from the QVision library.
/// @author PARP Research Group. University of Murcia, Spain.

#include <qvsfm.h>

#include <QFile>
#include <QTextStream>
bool writeMatchingsToBundlerMatchingsFile(const QString &fileName, const QVDirectedGraph< QVector<QVIndexPair> > &keyFrameCorrespondences)
	{
	QFile	matchingsFile(fileName);

	matchingsFile.open(QIODevice::WriteOnly | QIODevice::Text);

    QTextStream	outFile(&matchingsFile);

	bool cond = false;

	foreach(QVGraphLink link, keyFrameCorrespondences.keys())
		{
		if (cond)
			outFile << "\n";

		outFile << link.x() << " " << link.y();
		outFile << "\n" << keyFrameCorrespondences[link].count();
		foreach(QVIndexPair pair, keyFrameCorrespondences[link])
			outFile << "\n" << pair.first << " " << pair.second;

		cond = true;
		}

	matchingsFile.close(); 
	}

